home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ8607.ZIP
/
D16BIT.JUL
< prev
next >
Wrap
Text File
|
1986-07-31
|
7KB
|
226 lines
Screen # 0
( Support for Intel/Lotus Expanded Memory 13:16 08/14/85 )
This file contains some simple definitions to allocate
Expanded Memory space and use it for word arrays.
The usage within a PC/FORTH program would follow the sequence
EM-OPEN ( in program initialization code )
... d @EM ... ( various array accesses )
EM-CLOSE ( de-allocate memory )
If you fail to issue the EM-CLOSE, the Expanded Memory pages
will not be de-allocated and other programs may not be able
to obtain sufficient memory.
Copyright (c) 1985 Ray Duncan, Laboratory Microsystems Inc.
P. O. Box 10430, Marina del Rey, CA 90295
Screen # 1
( arrays & variables 13:16 08/14/85 )
FORTH DEFINITIONS HEX
( guaranteed device name for )
CREATE em_name ," EMMXXXX0" 0 C, ( Expanded Memory Manager )
67 CONSTANT em_int ( hex interrupt number for EMM )
-->
Screen # 2
( test for EMM device driver header method 14:02 08/14/85 )
( --- status ; =0 if EMM present, -1 if not present )
( compares name in presumed device driver to guaranteed name )
CODE ems? SI PUSH
DI, DI XOR ES, DI MOV ( pick up EMM )
DI, # em_int 4 * MOV ( int vector )
ES: ES, 2 [DI] MOV DI, # 0A MOV
SI, # em_name MOV CX, # 8 MOV
CLD REPZ BYTE CMPS ( compare driver name )
SI POP
1$ JNZ ( jump if EMM driver found )
AX, # 0 MOV 2$ JMP ( return FALSE flag )
1$: AX, # -1 MOV ( return TRUE flag )
2$: AX PUSH NEXT, END-CODE
-->
Screen # 3
( get EMM frame, EMM free pages 14:02 08/14/85 )
( --- segment ; get segment of the EMM page frame )
( segment is returned as 0 if function failed )
CODE em_frame AH, # 41 MOV
em_int INT
AH, AH OR 1$ JZ BX, # 0 MOV
1$: BX PUSH NEXT, END-CODE
( returns number of EMM pages which are currently available )
( --- free_pages total_pages )
CODE em_pages AH, # 42 MOV em_int INT
AH, AH OR 1$ JZ DX, # 0 MOV BX, DX MOV
1$: BX PUSH DX PUSH NEXT, END-CODE
-->
Screen # 4
( open EMM & allocate pages 15:45 08/14/85 )
( get an EMM handle and allocate EMM logical pages to it )
( pages --- handle | 0 )
CODE em_open BX POP
AH, # 43 MOV em_int INT
AH, AH OR 1$ JZ ( jump if no error )
DX, # 0 MOV ( if error return 0 )
1$: DX PUSH
2$: NEXT, END-CODE
-->
Screen # 5
( memory mapping 16:20 08/14/85 )
( map an EMM logical page owned by handle to a physical page )
( logical_page physical_page handle --- status; =0 if ok )
CODE em_map DX POP ( handle )
AX POP ( physical page # )
BX POP ( logical page # )
AH, # 44 MOV em_int INT
AH, AH OR 1$ JZ ( jump if no error )
AH, AL XCHG ( AL := error code )
AH, # 0 MOV 2$ JMP
1$: AX, # 0 MOV ( return 0 if no error )
2$: AX PUSH NEXT, END-CODE
-->
Screen # 6
( release page allocation 16:35 08/14/85 )
( release an EMM handle and all logical pages allocated to it )
( handle --- status )
CODE em_close DX POP AH, # 45 MOV
em_int INT
AH, AH OR 1$ JZ ( jump if no error )
AH, AL XCHG ( AL := error code )
AH, # 0 MOV 2$ JMP
1$: AX, # 0 MOV ( return 0 if no error )
2$: AX PUSH NEXT, END-CODE
-->
Screen # 7
( EM variables & misc defs 11:13 10/03/85 )
2VARIABLE $EM_USED ( bytes of EM assigned to arrays )
VARIABLE $EM_PID ( handle for FORTH from EM manager )
VARIABLE $EM_FRAME ( segment of EM paging frame )
( d1 --- d2 ; quick double number multiplies )
: D2* 2DUP D+ ;
: D4* D2* D2* ;
: D8* D4* D2* ;
( d --- ; compile a double number )
: D, HERE 2! 4 ALLOT ;
-->
Screen # 8
( EM array alignment, EM-CLOSE 14:02 10/04/85 )
( --- ; align EM on 2-byte boundary for single int array )
: WALIGN $EM_USED 2@ OVER 1 AND 0 D+
$EM_USED 2! ;
( --- ; release Expanded Memory allocation )
: EM-CLOSE $EM_PID @ DUP 0= ABORT" EM not opened"
em_close ABORT" Can't release memory"
$EM_PID OFF ;
-->
Screen # 9
( EM-OPEN 10:01 10/04/85 )
( --- ; establish availability of Expanded Memory & allocate )
: EM-OPEN $EM_PID @ IF EM-CLOSE THEN
ems? ABORT" Memory manager not installed"
em_frame DUP 0= ABORT" EM Frame not valid"
$EM_FRAME ! ( save EM paging segment )
em_pages SWAP DROP 4000 UM*
$EM_USED 2@ D<
ABORT" Insufficient expanded memory available"
$EM_USED 2@ 4000 UM/MOD SWAP
IF 1+ THEN ( round up to next page )
em_open DUP 0= ABORT" Can't get EMM handle"
$EM_PID ! ;
-->
Screen # 10
( EM-ARRAY word array 12:49 10/03/85 )
( d_cells --- ; compiling )
( d_cell# --- em_daddr ; executing )
: EM-ARRAY CREATE WALIGN ( word align EM ptr )
2DUP 1. D- D, ( highest cell # )
D2* ( *2 for # of bytes needed )
$EM_USED 2@ ( get current EM offset )
2DUP D, ( save it )
D+ $EM_USED 2! ( update EM offset )
DOES> DUP >R 2@ ( get # of cells declared )
2OVER DU< ABORT" Index out of bounds"
D2* ( cell# *2 for offset )
R> 4 + 2@ D+ ; ( + base offset )
-->
Screen # 11
( @EM !EM 13:05 10/03/85 )
( em_daddr --- n )
: @EM 4000 UM/MOD 0 ( pa_offs log_pa phys_pa )
$EM_PID @ em_map ABORT" @EM mapping error"
$EM_FRAME @ SWAP @L ;
( n em_daddr --- )
: !EM 4000 UM/MOD 0 ( pa_offs log_pa phys_pa )
$EM_PID @ em_map ABORT" !EM mapping error"
$EM_FRAME @ SWAP !L ;
DECIMAL CR CR .( EMM management routines loaded. )
CR ?WORKSPACE U. .( bytes left in dictionary. ) CR CR